package com.ztom.offer.v2;

/**
 * 剪绳子
 * <p>
 * https://leetcode-cn.com/problems/jian-sheng-zi-lcof/
 *
 * @author ZhangTao
 */
public class Code12CuttingRope {

    public int cuttingRope(int n) {
        if(n <= 3) return n - 1;
        int a = n / 3, b = n % 3;
        if(b == 0) return (int)Math.pow(3, a);
        if(b == 1) return (int)Math.pow(3, a - 1) * 4;
        return (int)Math.pow(3, a) * 2;
    }
}
